
var dataManager = require('../../../../utils/dataManager.js');
var GlobalData = require('../../../../utils/GlobalData.js');
var app = getApp();
Page({

  /**提现 */
  onBindbankcard: function () {
    /**绑定银行信息 */
    dataManager.OnRequestPost({ method: "getbankaccountlist", "token": GlobalData.token }, this.onWithdrawComplete, false, this.onError);
  },
  onWithdrawComplete(data) {
    GlobalData.bindInfo = data;
    dataManager.UseNavigateTo('../../homes/bindbankcard/bindbankcard', false);
  },
  onBindalipay: function () {
    dataManager.UseNavigateTo('../../homes/bindalipay/bindalipay', false);
  },
  /**前往帮助主页 */
  goHomeHelp: function () {
    this.setData({
      hidden: false
    })
    dataManager.UseNavigateTo('../../homes/help/homehelp/homehelp', false);
  },
  /**设置登录密码 */
  goSetLoginPassword: function () {

    this.setData({
      hidden: false
    })
    dataManager.UseNavigateTo('../../homes/setloginpsword/setloginpsword', false);
  },
  /**设置支付密码 */
  goSetPaypswd: function () {
    this.setData({
      hidden: false
    })
    dataManager.UseNavigateTo('../../homes/setpaypsword/setpaypsword?url=setting', false);
  },

  /**监听改变滑块 */
  switch1Change: function (e) {
    // console.log(e.detail.value, "滑块");
    this.setData({
      isOpenPayPass: e.detail.value ? 1 : 0
    })
    this.onSetWithoutCode();
  },

  onSetWithoutCode: function () {
    dataManager.OnRequestPost({ method: "modifyisopenpaypass", token: GlobalData.token, "password": this.data.inputPassWord, "isopenpaypass": this.data.isOpenPayPass }, this.onprocessWithoutCode);
  },
  onprocessWithoutCode: function (data) {
    dataManager.OnRequestPost({ method: "getagent", token: GlobalData.token }, this.onprocessHomeData);
  },
  onprocessHomeData: function (data) {
    GlobalData.homeData = GlobalData.clone(data);
    //设置免密成功
    this.setData({
      inputPassWord: "",
      isOpenPayPass: GlobalData.homeData["isopenpaypass"]
    })
  },
  /**
   * 页面的初始数据
   */
  data: {
    inputPassWord: "",
    isShowmianmi: false,
    isOpenPayPass: 0,
    switch1Checked: true,
    hidden: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    dataManager.removeBtnObserver("setting")
    // console.log(GlobalData.homeData, "on")
    this.setData({
      hidden: true
    })
    if (GlobalData.homeData && !GlobalData.homeData.isopenpaypass) {
      this.setData({
        isOpenPayPass: GlobalData.homeData.isopenpaypass,
        switch1Checked: GlobalData.homeData.isopenpaypass > 0 ? true : false
      })
    }

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})